package com.xzr.hospitalregister.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xzr.hospitalregister.R;
import com.xzr.hospitalregister.entity.DialogIpSelectItem;

import java.util.List;

/**
 * Created by Administrator on 2017/9/1.
 */

public class AdapterDialogIpSelect extends RecyclerView.Adapter<AdapterDialogIpSelect.MyHolder> {
    private Context context;
    private List<DialogIpSelectItem> data;

    public AdapterDialogIpSelect(Context context, List<DialogIpSelectItem> data) {
        this.context = context;
        this.data = data;
    }

    public interface OnItemClickListener {
        void onClick(int position);

        void onLongClick(int position);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.dialog_ip_select_item, null));
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        holder.name.setText(data.get(position).getCityName());
        holder.ip.setText(data.get(position).getCityIp());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        TextView name;
        TextView ip;

        public MyHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.tv_dialog_ip_select_item_cityName);
            ip = (TextView) itemView.findViewById(R.id.tv_dialog_ip_select_item_cityIp);
        }
    }
}
